<div data-extend-template="components/views/bst-modal.html">
  <h4 data-block="modal-header">Content Host Errata Management</h4>

  <div data-block="modal-body">
    <form id="errataActionForm" name="errataActionForm" class="form" method="post" action="/katello/remote_execution">
      <input type="hidden" name="remote_action" ng-value="errataActionFormValues.remoteAction"/>
      <input type="hidden" name="bulk_host_ids" ng-value="errataActionFormValues.bulkHostIds"/>
      <input type="hidden" name="bulk_errata_ids" ng-value="errataActionFormValues.bulkErrataIds"/>
      <input type="hidden" name="authenticity_token" ng-value="errataActionFormValues.authenticityToken"/>
      <input type="hidden" name="customize" ng-value="errataActionFormValues.customize"/>
      <input type="hidden" ng-if="allHostsSelected" name="scoped_search" ng-value="errataActionFormValues.scopedSearch"/>
    </form>

    <div bst-alert="info" ng-show="showConfirm">
      <span translate>
        Are you sure you want to apply the {{ table.numSelected }} selected errata to the content hosts chosen?
      </span>
      <div>
        <button type="button" class="btn btn-default" ng-click="showConfirm = false; installErrata()" translate>Yes</button>
        <button type="button" class="btn btn-default" ng-click="showConfirm = false;; table.working = false" translate>No</button>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-12">
        <div bst-global-notification></div>
      </div>
    </div>

    <div ng-show="katelloAgentPresent" data-extend-template="common/views/katello-agent-notice.html"></div>
    <div bst-feature-flag="remote_actions">
      <p bst-alert="warning" ng-hide="hostToolingEnabled">
        <span translate>
          Performing host package actions is disabled because Katello is not configured for Remote Execution or Katello Agent.
          </span>
      </p>
    </div>

    <div ng-show="showTable()" data-extend-template="layouts/partials/table.html">
      <div data-block="list-actions">
        <button class="btn btn-default" type="button"
                ng-disabled="table.numSelected === 0 || table.working"
                ng-click="fetchErrata()">
          <span translate>Refresh Table</span>
        </button>

        <span uib-dropdown class="btn-group">
          <button class="btn btn-primary" type="button"
                  ng-disabled="table.numSelected === 0 || table.working || table.numSelected === 0 || !hostToolingEnabled"
                  ng-click="showConfirm = true;">
            <span translate>Install Selected</span>
          </button>
          <button uib-dropdown-toggle class="btn btn-primary" type="button"
                  ng-show="remoteExecutionPresent"
                  ng-disabled="table.numSelected === 0 || table.working || table.numSelected === 0"
                  type="button" id="use-remote-execution">
            <span class="caret"></span>
          </button>

          <ul uib-dropdown-menu class="dropdown-menu-right" role="menu" aria-labelledby="use-remote-execution">
            <li ng-show="katelloAgentPresent" role="presentation"><a ng-click="installErrataViaKatelloAgent()" role="menuitem" translate>via Katello agent</a></li>
            <li role="presentation"><a ng-click="installErrataViaRemoteExecution(false)" role="menuitem" translate>via remote execution</a></li>
            <li role="presentation"><a ng-click="installErrataViaRemoteExecution(true)" role="menuitem" translate>via remote execution - customize first</a></li>
          </ul>
        </span>
      </div>

      <span data-block="no-rows-message" translate>
        There are no Errata associated with this Content Host to display.
      </span>

      <span data-block="no-search-results-message" translate>
        Your search returned zero Errata.
      </span>

      <div data-block="table">
        <div data-extend-template="layouts/select-all-results.html"></div>

        <table class="table table-striped table-bordered" ng-class="{'table-mask': table.working}">
         <thead>
           <tr bst-table-head row-select>
             <th bst-table-column="type" translate>Type</th>
             <th bst-table-column="errata_id" translate>Id</th>
             <th bst-table-column="title" translate>Title</th>
             <th bst-table-column="issued" translate>Issued</th>
             <th bst-table-column="content_host_affected" translate>Affected Hosts</th>
           </tr>
         </thead>

         <tbody>
           <tr bst-table-row ng-repeat="erratum in table.rows | filter:errataFilter" row-select="erratum">
             <td class="small" bst-table-cell>
                 {{ erratum.type }}
             </td>
             <td class="small" bst-table-cell>
               <a ng-click="transitionToErrata(erratum)">
                 {{ erratum.errata_id }}
               </a>
             </td>

             <td bst-table-cell>{{ erratum.title }}</td>
             <td class="small" bst-table-cell>{{ erratum.issued }}</td>
             <td class="small" bst-table-cell class="number-cell">
               <span> {{ erratum.affected_hosts_count }} </span>
             </td>
           </tr>
         </tbody>
        </table>
      </div>
    </div>

    <div name="errataDetails" ng-show="showErrata">
      <a ng-click="showErrata = false">
        <i class="fa fa-double-angle-left"></i>
        {{ "Back To Errata List" | translate }}
      </a>

      <h3>{{ 'Errata Details' | translate }}</h3>

      <h3>{{ erratum.errata_id }} </h3>

      <div class="details details-full">
        <section>

          <div class="detail">
            <span class="info-label" translate><b>Type</b></span>
            <span class="info-value">{{ erratum.type }}</span>
          </div>
          <div class="detail">
            <span class="info-label" translate><b>Title</b></span>
            <span class="info-value">{{ erratum.title }}</span>
          </div>
          <div class="detail">
            <span class="info-label" translate><b>Issued</b></span>
            <span class="info-value">{{ erratum.issued }}</span>
          </div>
          <div class="detail">
            <span class="info-label" translate><b>Updated</b></span>
            <span class="info-value">{{ erratum.updated }}</span>
          </div>
          <div class="detail">
            <span class="info-label" translate><b>Reboot Suggested</b></span>
            <span class="info-value">{{ erratum.reboot_suggested }}</span>
          </div>

          <div class="detail">
            <span class="info-label" translate><b>Description</b></span>
            <span class="info-value">
              <p ng-repeat="paragraph in erratum.description.split('\n\n')">
                {{ paragraph }}
              </p>
            </span>
          </div>

          <div class="detail">
            <span class="info-label" translate><b>Solution</b></span>
            <span class="info-value">
              <p ng-repeat="paragraph in erratum.solution.split('\n\n')">
                {{ paragraph }}
              </p>
            </span>
          </div>

          <div class="detail">
            <span class="info-label" translate><b>Packages</b></span>
            <span class="info-value">
              <ul>
                <li ng-repeat="package in erratum.packages">
                  {{ package }}
                </li>
              </ul>
            </span>
          </div>

          <div class="detail">
            <span class="info-label" translate><b>Module Streams</b></span>
            <span class="info-value">
              <ul>
                <li ng-repeat="moduleStream in erratum.module_streams">
                  {{ moduleStream.name + ":" + moduleStream.stream }}
                  <ul>
                    <li ng-repeat="package in moduleStream.packages">
                      {{ package }}
                    </li>
                  </ul>
                </li>
              </ul>
            </span>
          </div>
        </section>
      </div>
	</div>
  </div>

  <div data-block="modal-footer">
    <button type="button" class="btn btn-primary" ng-click="ok()" translate>
      Done
    </button>
  </div>
</div>
